<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;
use Illuminate\Http\Request;
use App\Repositorys\PersonRepository;
use App\User;
use App\Province;
use App\Person;
use App\Repositorys\HomeRepository;



class HomeController extends Controller
{

    protected $home;
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct(HomeRepository $home)
    {
        $this->middleware('auth');
        $this->home = $home;
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $year_archives = $this->home->years();

        $reg_addrs = $this->home->regAddr();

        $temp_addrs_map = $this->home->tempAddr();

        $addon_data = $this->home->addonData();

        extract($addon_data);

        return view('home', compact('year_archives', 'temp_addrs_map', 'reg_addrs', 'user_count', 'person_count', 'person_today_count'));
    }


    public function optimize()
    {
        $result = \DB::select('OPTIMIZE TABLE `persons`');

        if ($result) {
            return redirect('home/setting')->with('success', '优化数据库成功');
        } else {
            return redirect()->back()->withInput()->withErrors( );
        }


    }

    public function setting()
    {
        return view('home/setting');
    }

    public function api()
    {

        return view('home/api');
    }

    public function upload_master()
    {
        echo "jiejia branch";

        echo "jiejia has fixed issue-101";
    }
}
